package response

var responseCodeMsgMap = map[int]string{
	CODE_SUCCESS:               MSG_SUCCESS,
	CODE_FAILURE:               MSG_FAILURE,
	CODE_CLIENT_ERROR:          MSG_CLIENT_ERROR,
	CODE_SERVER_ERROR:          MSG_SERVER_ERROR,
	CODE_NOT_FOUND:             MSG_NOT_FOUND,
	CODE_UNAUTHORIZED:          MSG_UNAUTHORIZED,
	CODE_SERVICE_ERROR:         MSG_SERVICE_ERROR,
	CODE_UTIL_ERROR:            MSG_UTIL_ERROR,
	CODE_INVALID_PARAMS:        MSG_INVALID_PARAMS,
	CODE_INVALID_METHOD:        MSG_INVALID_METHOD,
	CODE_INVALID_URL:           MSG_INVALID_URL,
	CODE_TOKEN_ERROR:           MSG_TOKEN_ERROR,
	CODE_TOKEN_EXPIRED:         MSG_TOKEN_EXPIRED,
	CODE_TOKEN_INVALID:         MSG_TOKEN_INVALID,
	CODE_TOKEN_NOT_FOUND:       MSG_TOKEN_NOT_FOUND,
	CODE_TOKEN_FORMAT_ERROR:    MSG_TOKEN_FORMAT_ERROR,
	CODE_TOKEN_SIGNATURE_ERROR: MSG_TOKEN_SIGNATURE_ERROR,
	CODE_TOKEN_USER_NOT_FOUND:  MSG_TOKEN_USER_NOT_FOUND,
	CODE_TOKEN_USER_DISABLED:   MSG_TOKEN_USER_DISABLED,
	CODE_TOKEN_USER_LOCKED:     MSG_TOKEN_USER_LOCKED,
	CODE_TOKEN_USER_EXPIRED:    MSG_TOKEN_USER_EXPIRED,
	CODE_TOKEN_USER_NOT_MATCH:  MSG_TOKEN_USER_NOT_MATCH,
}

/**
 * Matches the response code to the corresponding message in the mapping.
 * If the code does not exist in the mapping, it returns "unknown error".
 * @param code int
 * @return msg string
 */
func ResponseCode2Msg(code int) string {
	msg, exists := responseCodeMsgMap[code]
	if !exists {
		return "unknown error"
	}
	return msg
}
